import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-10-05
 * Time: 21:43
 */
public class Test100 {

    public static void sortColors(int[] num) {
        int i = 0, n = num.length;
        int left = -1, right = n;

        while(i < right) {
            if(num[i] == 0) {
                swap(num,i++,++left);
            }else if(num[i] == 1) {
                i++;
            }else {
                swap(num,i,--right);
            }
        }
    }

    public static void swap(int[] num, int i, int j) {
        int tmp = num[i];
        num[i] = num[j];
        num[j] = tmp;
    }


    public static void main(String[] args) {
        int[] num = {2,0,2,1,1,0};
        sortColors(num);
        System.out.println(Arrays.toString(num));
    }
}
